import { Color, Ray3, Vector3 } from "@script/index";

const light_color = Color.white;
const light_dir = Ray3.light;

export default class Phong {
  private diffuse: Color;
  private specular: Color;
  private readonly shininess: number;
  reflectiveness: number;

  constructor(diffuse: Color, specular: Color, shininess: number, reflectiveness?) {
    this.diffuse = diffuse;
    this.specular = specular;
    this.shininess = shininess;
    this.reflectiveness = reflectiveness;
  }

  sample(ray: Ray3, position: Vector3, normal: Vector3) {
    let n_dot_l = normal.dot(light_dir);
    let h = (light_dir.subtract(ray.direction)).normalize();
    let n_dot_h = normal.dot(h);
    let diffuse = this.diffuse.multiply(Math.max(n_dot_l, 0));
    let specular = this.specular.multiply(Math.pow(Math.max(n_dot_h, 0), this.shininess));
    return light_color.modulate(diffuse.add(specular));
  }
}